//
//  MJWordJudge.m
//  测试1.1
//
//  Created by 王志盼 on 15/2/5.
//  Copyright (c) 2015年 王志盼. All rights reserved.
//

#import "MJWordJudge.h"

@implementation MJWordJudge


- (void)searchWithString:(NSString *)string
{
    int pos = 0;
    int top = 0;
    BOOL flag = false;
    for (int i= 0; i < string.length; i++) {
        
        char ch = [string characterAtIndex:i];
        if (ch < 0) continue;
        if ((ch>='a' && ch<='z') || (ch>='A' && ch<='Z')) {
            
            if (!flag) {
                flag = true;
                top = pos = i;
            }
            //NSLog(@"----%c--%d--%d--%d",ch,i,pos,top);
            top++;
        }
        else
        {
            flag = false;
            if (pos != top) {
                
                NSRange range;
                range.length = top - pos;
                range.location = pos;
                
                if ([self.delegate respondsToSelector:@selector(wordJudgeWithRange:)]) {
                    [self.delegate wordJudgeWithRange:range];
                }
            }
            top = pos = i;
        }
    }
}
@end